home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 312_01 / lbi2mak.awk < prev    next >
Text File  |  1990-04-21  |  13KB  |  281 lines

  1. #  HEADER:        ;
  2. #  TITLE:         Intel Librarian input-file object file extractor
  3. #  DATE:          09/28/1989;
  4. #  VERSION:       1.1;
  5. #  DESCRIPTION:   "An AWK program which scans a librarian input-file
  6. #                 and builds a batch file which will in turn
  7. #                 produce a make-file.  Requires the services of a
  8. #                 source-file dependency generator (such as cincdep)."
  9. #  KEYWORDS:      Makefile, make, include, dependency generator;
  10. #  SYSTEM:        MS-DOS;
  11. #  WARNINGS:      "PolyAwk will generate false matches to lines
  12. #                 beginning with non-ASCII (i.e. 128..256) chars."
  13. #  FILENAME:      LBI2MAK.AWK;
  14. #  SEE-ALSO:      CINCDEP.AWK, TLR2MAK.AWK, AINCDEP.AWK, PINCDEP.AWK;
  15. #  AUTHORS:       James Yehle;
  16. #  COMPILERS:     PolyAWK, Mortice Kern AWK, Rob Duff's PC-AWK 2.0;
  17. #-----------------------------------------------------------------------------
  18. #
  19. #  Lbi2mak.awk              Last modified  Sep 28, 1989  22:22
  20. #
  21. #     Scans an Intel library make (from scratch) input file to produce
  22. #     to produce a batch file for use with dependency generator(s)
  23. #     to build a set of make-file dependency lists (and eventually a make-file)
  24. #
  25. #  Jim Yehle
  26. #
  27. # . . . Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . .
  28. #
  29. #  1.1  Sep 10 89  JRY  Added legal-filename-char regular expression
  30. #  1.0  Sep 10 89  JRY  Initial creation--from cf2mak.awk v 1.6
  31. # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  32. #
  33. #  Usage is:
  34. #    awk -f lbi2mak.awk filename.lbi outfile=[path]filename
  35. #        lc=command lcf=[p][n][e] [>batchfile]
  36. #     where outfile gets the conglomerated dependency generator output
  37. #     Order of command-line parameters (save for "-f ..." 
  38. #      and ">batchfile") is irrelevant, but identifiers must be in lower case.
  39. #     lc is the compile command (no spaces allowed)
  40. #     lcf controls which components of the source file's name get
  41. #         included in the link command line: p = directory path,
  42. #         n = name, e = extension.
  43. # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  44. #
  45. #  Takes an Intel librarian input file as input.
  46. #  Generates an executable-dependency list at the start of outfile,
  47. #  followed by the link command and the primary (executable) file name.
  48. #  Extracts all object files which are to be added to the library.
  49. #  Generates a batch file line, for each object file found, of the form:
  50. #   comdpre srcfile "incpath="incpath "objname="file.obj
  51. #     "cc="cc "ccf="ccf comdmid outfile comdpost
  52. #  unless the source file can't be found, in which case it makes this batch file line:
  53. #   comdpre "__NOFILE__ objname="file.obj "cc= ccf= " comdmid outfile comdpost
  54. #  The search for source files covers C, assembly, and PL/M path and extensions.
  55. #
  56. #  Assumes object file names contain only these chars: [^\\]*.[Oo][Bb][Jj]
  57. #  Assumes FILENAME ends with .LBI or .lbi and that primary target (library)
  58. #   file name is made by replacing .LBI with exe_ext.
  59. #
  60. #-----------------------------------------------------------------------------
  61. #
  62. BEGIN {
  63.    # Set various strings used in building batch-file command lines
  64.    # (these should probably get passed in as lbi2mak command-line arguments)
  65.  
  66.    #  Lbi2mak supports several languages.  Each language must have
  67.    #   1) a source file name extension (to replace ".obj" in searches)
  68.    #   2) a source directory pathname (stuck on front of file name during search)
  69.    #   3) an include-file directory whose name to pass to a dependency scanner
  70.    #   4) a compiler command to pass to dependency scanner (no spaces allowed)
  71.    #   5) controls for filename pathname/extension inclusion in compile command line
  72.    #   6) a dependency generator awk program
  73.  
  74. # ------------- User-customized section ------------------------------
  75.    # Language 1 is C
  76.    ext[1] = ".c"
  77.    path[1]    = "s:\\c\\"
  78.    ipath[1]   = "s:\\c\\inc\\"
  79.    cc[1] = "ccd"
  80.    ccf[1] = "n"
  81.    depgen[1] = "s:\\awk\\cincdep.awk"
  82.    # Language 2 is PL/M
  83.    ext[2] = ".plm"
  84.    path[2]  = "s:\\plm\\"
  85.    ipath[2] = "s:\\plm\\inc\\"
  86.    cc[2] = "plmld"
  87.    ccf[2] = "n"
  88.    depgen[2] = "s:\\awk\\pincdep.awk"
  89.    # Language 3 is assembly
  90.    ext[3] = ".a28"
  91.    path[3]  = "s:\\asm\\"
  92.    ipath[3] = "s:\\asm\\inc\\"
  93.    cc[3] = "asm"
  94.    ccf[3] = "n"
  95.    depgen[3] = "s:\\awk\\aincdep.awk"
  96.  
  97.    #    allpre      Leading line(s) of entire batch file
  98.    #    allpost     Trailing line(s) of entire batch file
  99.    #    comment     Comment-line lead-in: DOS "REM" or "ECHO", iRMX ";"
  100.    #    comdpre     Command line prefix
  101.    #    comdmid     Command line midle: between source & output file names
  102.    #    comdpost    Command line suffix
  103.    #    exe_ext     Executable file extension (e.g. ".exe" or ".com" for DOS)
  104.    #    linecont    Line-continuation EOL char: snake " /", unix make "\"
  105.    #    fname_chars Regular expression specifying any single legal char
  106.    #                which can appear in a file name.  Must exclude 
  107.    #                directory path separator character! (DOS \, UNIX /)
  108.    allpre = "echo off"
  109.    allpost = "echo on"
  110.    comment = "echo "
  111.    comdpre = "awk -f "
  112.    comdmid = " >>"
  113.    comdpost = ""
  114.    exe_ext = ".LIB" 
  115.    linecont = " \\"
  116.    fname_chars = "[^\\\\ :]" # Unix "[^/ ]"; used to use "[A-Za-z0-9_]"
  117. # ------------ End of user-customized section ------------------------
  118. #
  119.    co = "CON"   # Console-out: MS-DOS "CON", iRMX ":co:", unix "/dev/tty"
  120.    debug = 0    # 0=off, 1=verbose, 2=main-level debug, 3= adds functions
  121.  
  122.    print "lbi2mak.awk  Library input-file object-file extractor  v 1.1" > co
  123.  
  124.    outfile = get_cl_param( "outfile=", 0)
  125.    lc = get_cl_param( "lc=", 0)
  126.    lcf = get_cl_param( "lcf=", 0)
  127.  
  128.    print allpre
  129.    if (debug) print allpre >co
  130.  
  131. }
  132. #
  133. $0 ~ /^[ \t]*[Aa][Dd][Dd][ \t]+/  ||  $0 ~ /^[ \t]*[Aa][ \t]+/ {
  134.    # Object file name has been extracted (into $2)
  135.    fullobjname = $2
  136.    for (flix=1; flix in flist; flix++)
  137.       ;
  138.    flist[flix] = fullobjname # Add to array
  139.    if (debug>1) print "NR " NR ", fullobjname = " fullobjname >co
  140.  
  141.    # Split object file name into Path, Name and Extension components
  142.    split_filename( fullobjname, objnameparts, fname_chars)
  143.    if (debug>1) print "objnameparts[\"name\"] = " objnameparts["name"] >co
  144.  
  145.    # Generate one batch file line
  146.    look_for_source_file( objnameparts["name"], fullobjname)
  147. }
  148. #
  149. END {
  150.    print allpost
  151.    if (debug) print allpost >co
  152.  
  153.    # Generate executable-file dependency list (into outfile)
  154.    # Split primary link-configuration file name into Path, Name, and Extension 
  155.    split_filename( FILENAME, exefile, fname_chars)
  156.    exefile["ext"] = exe_ext  # Change it from ".lbi"
  157.    # Print primary (executable) file name before list (left of colon)
  158.    primarydependent = sprintf( "%s%s%s", exefile["path"],
  159.                                exefile["name"], exefile["ext"])
  160.    printf( "%s:", primarydependent) >outfile
  161.    if (debug) printf( "%s:", primarydependent) >co
  162.    linelen = length(primarydependent) + 1
  163.    for (i=1; i in flist; i++) {
  164.       # If line will be too long, put out a line-continuation char and newline
  165.       if (linelen + 1 + length(flist[i]) + length(linecont)  > 79) {
  166.          printf( "%s\n", linecont) >outfile
  167.          if (debug) printf( "%s\n", linecont) >co
  168.          # On the new line, tab out to underneath the first included file name
  169.          for (linelen=0; linelen<length(primarydependent)+1; ++linelen) {
  170.             printf(" ") >outfile
  171.             if (debug) printf(" ") >co
  172.          }
  173.       }
  174.       printf( " %s",  flist[i] ) >outfile
  175.       if (debug) printf( " %s",  flist[i] ) >co
  176.       linelen += length(flist[i]) + 1
  177.    }
  178.    # Build the link command line's only parameter: the filename
  179.    #  depending on options specified in lcf command-line param
  180.    link_comd_filename = sprintf( "%s%s%s",
  181.                                  lcf ~ /[Pp]/? exefile["path"] : "",
  182.                                  lcf ~ /[Nn]/? exefile["name"] : "",
  183.                                  lcf ~ /[Ee]/? exefile["